using NodeCanvas.Variables;

namespace NodeCanvas.Actions
{
	[Category("✫ Utility")]
	[Description("Send a graph event. If global is true, all graphs in scene will receive this event. Use along with the 'Check Event' Condition")]
	[AgentType(typeof(GraphOwner))]
	public class SendEvent : ActionTask
	{
		[RequiredField]
		public BBString eventName;

		public BBFloat delay;

		public bool global;

		protected override string info
		{
			get
			{
				return string.Concat((!global) ? string.Empty : "Global ", "Send [", eventName, "]", (!(delay.value > 0f)) ? string.Empty : string.Concat(" after ", delay, " sec."));
			}
		}

		protected override void OnUpdate()
		{
			if (base.elapsedTime > delay.value)
			{
				if (global)
				{
					Graph.SendGlobalEvent(eventName.value);
				}
				else
				{
					(base.agent as GraphOwner).SendEvent(eventName.value);
				}
				EndAction();
			}
		}
	}
}
